{% extends 'layout.html' %}
{% load mytags %}
{% block content %}
    <div class="row">
        <div class="col-md-12">
            <div class="box box-warning">
                <!--<div class="box-header with-border">
                    <h3 class="box-title">配置项目</h3>
                    <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i
                                class="fa fa-chevron-up"></i>
                        </button>
                        <div class="btn-group">
                            <button type="button" class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown">
                                <i class="fa fa-wrench"></i></button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="#">Action</a></li>
                                <li><a href="#">Another action</a></li>
                                <li><a href="#">Something else here</a></li>
                                <li class="divider"></li>
                                <li><a href="#">Separated link</a></li>
                            </ul>
                        </div>
                        <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i>
                        </button>
                    </div>
                </div>
                 /.box-header -->
                <div class="box-body">
                    <div class="col-md-12">
                        <form id="project_form" method="post" class="form-horizontal">
                            <div class="form-group">
                                <label class="control-label col-sm-2">项目名<span class="text-red">*</span>：</label>
                                <div class="col-sm-8">
                                    {{ project_form.name }}
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">项目环境<span class="text-red">*</span>：</label>
                                <div class="col-sm-8">
                                    <select name="env" class="form-control">
                                        {% for env in project_env %}
                                            <option value="{{ env.0 }}">{{ env.1 }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <h4><i class="fa fa-map-marker orange"></i> Repo</h4>
                            <ul id="myTab" class="nav nav-tabs">
                                <li class="active"><a href="#git"><i class="fa fa-gitlab"></i> git</a></li>
                                <li><a href="#svn"><i class="fa fa-get-pocket"></i> svn</a></li>
                            </ul>
                            <div style="height:15px;"></div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">仓库地址<span
                                        class="text-red">*</span>：</label>
                                <div class="col-sm-8">
                                    {{ project_form.repo_url }}
                                </div>
                            </div>
                            <div id="tabcontent" class="tab-content">
                                <div id="git" class="tab-pane active">

                                </div>
                                <div id="svn" class="tab-pane">
                                    <div class="form-group">
                                        <label class="control-label col-sm-2">用户名：</label>
                                        <div class="col-sm-3">
                                            {{ project_form.repo_username }}
                                        </div>
                                        <label class="control-label col-sm-2">密码：</label>
                                        <div class="col-sm-3">
                                            {{ project_form.repo_password }}
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="row">
                                <div class="col-sm-4">
                                    <h4><i class="fa fa-dashboard orange"></i> 宿主机</h4>
                                    <label class="control-label">代码检出仓库<span
                                            class="text-red">*</span>：</label>
                                    {{ project_form.deploy_from }}
                                    <label class="control-label">排除文件：</label>
                                    {{ project_form.excludes }}
                                </div>
                                <div class="col-sm-4">
                                    <h4><i class="fa fa-cloud-upload orange"></i> 目标机器</h4>
                                    <label class="control-label">www用户<span
                                            class="text-red">*</span>：</label>
                                    {{ project_form.release_user }}
                                    <label class="control-label">webroot<span
                                            class="text-red">*</span>：</label>
                                    {{ project_form.release_to }}
                                    <label class="control-label">发布版本库<span
                                            class="text-red">*</span>：</label>
                                    {{ project_form.release_library }}
                                    <label class="control-label">版本保留数<span
                                            class="text-red">*</span>：</label>
                                    {{ project_form.keep_version_num }}

                                    <label class="control-label">机器列表<span
                                            class="text-red">*</span>：</label>
                                    {{ project_form.hosts }}

                                </div>
                                <div class="col-sm-4">
                                    <h4><i class="fa fa-tasks orange"></i> 高级任务</h4>

                                    <label class="control-label">pre_deploy：</label>
                                    {{ project_form.pre_deploy }}
                                    <label class="control-label">post_deploy：</label>
                                    {{ project_form.post_deploy }}
                                    <label class="control-label">pre_release：</label>
                                    {{ project_form.pre_release }}
                                    <label class="control-label">post_release：</label>
                                    {{ project_form.post_release }}
                                    <label class="control-label">post_release_delay：</label>
                                    {{ project_form.post_release_delay }}


                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">分支/tag上线：</label>
                                <div class="col-sm-8">
                                    <div class="radio i-checks">
                                        <label data-toggle="tooltip" title="测试环境推荐选项，可以选择branch+commit">
                                            <input type="radio" checked="" value="branch" name="repo_mode">branch
                                        </label>
                                        <label data-toggle="tooltip" title="生产环境推荐选项">
                                            <input type="radio" value="tag" name="repo_mode"> tag</label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">是否开启审核：</label>
                                <div class="col-sm-8">
                                    <div class="radio i-checks">
                                        <label data-toggle="tooltip" title="用户提交上线任务需要审核方可上线">
                                            <input type="radio" checked="" value="1" name="is_audit"> 是
                                        </label>
                                        <label data-toggle="tooltip" title="生产环境推荐选项">
                                            <input type="radio" value="0" name="is_audit"> 否</label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">是否开启Saltstack：</label>
                                <div class="col-sm-8">
                                    <div class="radio i-checks">
                                        <label> <input type="radio" checked="" value="1" name="is_salt"> 是
                                        </label>
                                        <label> <input type="radio" value="0" name="is_salt"> 否</label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">是否启用：</label>
                                <div class="col-sm-8">
                                    <div class="radio i-checks" data-toggle="tooltip" title="关闭时，用户不能对此项目发起上线">
                                        <label> <input type="radio" checked="" value="1" name="status">是
                                        </label>
                                        <label> <input type="radio" value="0" name="status"> 否</label>
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button id="submit_button" class="btn btn-default" type="submit">保存</button>
                                    <button class="btn btn-white" type="reset">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block self_footer_js %}
    <script>
        $(function () {
            $('#myTab a').click(function (e) {
                e.preventDefault()
                $(this).tab('show')
            });

            //$("[data-toggle='tooltip']").tooltip();

            $('#project_form').validator({
                timely: 2,
                theme: "yellow_right_effect",
                stopOnError: true,
                fields: {
                    "name": {
                        rule: "required",
                        tip: "项目名",
                        ok: ""
                    },
                    "repo_url": {
                        rule: "required",
                        tip: "仓库地址",
                        ok: ""
                    },
                    "deploy_from": {
                        rule: "required",
                        tip: "检出仓库位置",
                        ok: ""
                    },
                    "release_user": {
                        rule: "required",
                        tip: "用户",
                        ok: ""
                    }
                    ,
                    "release_to": {
                        rule: "required",
                        tip: "wwwroot",
                        ok: ""
                    }                    ,
                    "release_library": {
                        rule: "required",
                        tip: "版本库",
                        ok: ""
                    },
                    "keep_version_num": {
                        rule: "required;integer(+)",
                        tip: "版本保留数",
                        ok: ""
                    }
                    ,
                    "hosts": {
                        rule: "required",
                        tip: "待部署主机列表",
                        ok: ""
                    }
                },
                valid: function (form) {
                    form.submit();
                }
            });
        });
    </script>
{% endblock %}